package bintree.heap.leetcode;

import java.util.LinkedHashMap;
import java.util.Map;
import java.util.Set;

/**
 * 建立一个Map 遍历打印 Key和value
 * @author haomin
 * @date 2022/03/25 14:40
 **/
public class MapToSet {
    public static void main(String[] args) {
        String[] s = {"abc","cba","cba","bca"};
        fun(s);
    }

    private static void fun(String[] words) {

        LinkedHashMap<String,Integer> map = new LinkedHashMap<>();
        for(String word:words){
            map.put(word,map.getOrDefault(word,0)+1);
        }

        Set<Map.Entry<String,Integer>> entrySet = map.entrySet();
        for(Map.Entry<String,Integer> s : entrySet){
            System.out.println(s.getKey() +" + "+ s.getValue());
        }
    }

}